# some variables
BUILD_NUMBER=50200

BUILD_DATE=25062014

OBJECTS=\
'$(MAKEDIR)\obj\entry.o' \
'$(MAKEDIR)\obj\init.o' \
'$(MAKEDIR)\obj\printf.o' \
'$(MAKEDIR)\obj\printfb.o'\
'$(MAKEDIR)\obj\memory_init.o' \
'$(MAKEDIR)\obj\memory_page_alloc.o' \
'$(MAKEDIR)\obj\kernel_lock-1.o' \
'$(MAKEDIR)\obj\kernel_malloc.o' \
'$(MAKEDIR)\obj\kernel_memory_space.o' \
'$(MAKEDIR)\obj\cpp_runtime_main.o'

LD=$(APOLLOCOMPILERDIR)/x86_64-elf-ld

GCC=$(APOLLOCOMPILERDIR)/x86_64-elf-gcc -D__BUILD_NUMBER__=$(BUILD_NUMBER) -D__BUILD_DATE__=$(BUILD_DATE) \
-D__GCC_CROSS__ \
-Wall -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable -Wno-comment \
-Wimplicit-function-declaration -m64 -ffreestanding -nostdlib -mcmodel=large -mno-red-zone \
-mno-3dnow -Werror -O2

GPP=$(APOLLOCOMPILERDIR)/x86_64-elf-g++ -D__BUILD_NUMBER__=$(BUILD_NUMBER) -D__BUILD_DATE__=$(BUILD_DATE) \
-D__GCC_CROSS__ -std=c++0x\
-Wall -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable -Wno-comment \
-m64 -ffreestanding -nostdlib -mcmodel=large -mno-red-zone -mno-3dnow -Werror -O2 \


all:
# set the path to include tools
	set PATH=$(APOLLOCYGWINDIR)\bin;$(APOLLOTOOLSDIR);$(PATH)

# build cpp runtime code
	bash --login -c "$(GPP) -o '$(MAKEDIR)\obj\cpp_runtime_main.o' -c '$(MAKEDIR)\cpp_runtime_main.cpp'"

# build the entry code
	bash --login -c "nasm -w+error -f elf64 -o '$(MAKEDIR)\obj\entry.o' '$(MAKEDIR)\entry.asm'"
	bash --login -c "nasm -w+error -f elf64 -o '$(MAKEDIR)\obj\printfb.o' '$(MAKEDIR)\printf.asm'"
	bash --login -c "$(GCC) -o '$(MAKEDIR)\obj\init.o' -c '$(MAKEDIR)\init.c'"
	bash --login -c "$(GCC) -o '$(MAKEDIR)\obj\printf.o' -c '$(MAKEDIR)\printf.c'"

# build common code
	bash --login -c "nasm -w+error -f elf64 -o '$(MAKEDIR)\obj\kernel_lock-1.o' '$(MAKEDIR)\lock_no_IRQ.asm'"

# build the memory manager code
	bash --login -c "$(GCC) -o '$(MAKEDIR)\obj\memory_init.o' -c '$(MAKEDIR)\memory_init.c'"
	bash --login -c "$(GCC) -o '$(MAKEDIR)\obj\memory_page_alloc.o' -c '$(MAKEDIR)\memory_page_alloc.c'"
	bash --login -c "$(GCC) -o '$(MAKEDIR)\obj\kernel_malloc.o' -c '$(MAKEDIR)\kernel_malloc.c'"
	bash --login -c "$(GCC) -o '$(MAKEDIR)\obj\kernel_memory_space.o' -c '$(MAKEDIR)\kernel_memory_space.c'"


# stick it all together
	bash --login -c "$(LD) -T '$(MAKEDIR)\link-64.ld' -o '$(MAKEDIR)\Kernel.sys' $(OBJECTS)"

